<?php
include 'headerN.php';
include 'conexaoMysql.php';
$crud = new Crud();

$sql = "SELECT tbInscricoesId, tbUsuariosNome, tbInscricoesIdTurma FROM tbInscricoes, tbUsuarios WHERE
tbInscricoes.tbInscricoesIdUsuario = tbUsuarios.tbUsuariosId";
$execulta = mysql_query($sql);
$div = 0;

$data = date('Y-m-d');

if (isset($_POST['acao']) && $_POST['acao'] == "enviar") {

    $campo = $_POST['vl'];
    //var_dump($campo);
    foreach ($campo as $value) {
        $inseri = "INSERT INTO tbFrequencia (tbFrequenciaIdTurma, tbFrequenciaIdParticipante) SELECT tbInscricoesIdTurma, 
                          tbInscricoesIdUsuario FROM tbInscricoes WHERE tbInscricoesId = $value";
        //echo "$iseri<br>";
        $grava = mysql_query($inseri);
    }
    //header("location:frequencia.php");
}
?>
<div class="tbl_conteudo">
    <div class="topo_lista">
        <div class="edicao">
            Lista de Presença
        </div>

    </div>
        <div id="contactform">
            <form id="form12" action="frequencia.php" method="POST" ><br>

                <table cellpadding="1" border="1px">
                    <thead>
                        <tr>
                            <th width="2%">Presença</th>
                            <th width="2%">Nº de Insc.</th>

                            <th width="20%">Participante</th>
                            <th width="10%">Turma</th>
                            <th width="10%">Data da Presença</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $data = $crud->inverterData($data, '-');
                        while ($linha = mysql_fetch_array($execulta)) {

                            if ($div % 2 == 0)
                                echo "<tr class=zebra0>"; else
                                echo "<tr class=zebra1>"; $div++;

                            echo "<td align=center><input type=checkbox checked name=vl[] value=" . $linha[0] . "></td>";

                            echo '<td>' . $linha[0] . '</td>';
                            echo '<td>' . $linha[1] . '</td>';
                            echo "<td>" . $linha[2] . "</td>";
                            echo "<td align=center>$data</td>";
                        }
                        ?>
                    </tbody>	
                </table>
                <input type="hidden" name="acao" value="enviar">
                <input class="button" type="submit" name="enviar" value="Salvar" />
            </form>
        </div>
    </div>
    <?php
    include 'footerN.php';
    ?>